package svc;

import constants.Constants;
import dao.BWDao;
import domain.bw.BodyWeight;
import domain.bw.BodyWeightOpen;

public class BWSvc {
	BWDao dao = new BWDao();
	
	public BodyWeight getBodyWeightDetails(int fileNo){
		BodyWeight result = new BodyWeight();
		BodyWeightOpen open = getBodyWeightOpen(fileNo);
		
		result.setBwOpen(getBWOpen(open));
		result.setBwPreg(dao.getBodyWeightPreg());
		return result;
	}
	
	public BodyWeightOpen getBodyWeightOpen(int fileNo){
		return dao.getBodyWeightOpen(fileNo);
	}

	public double[][][] getBWOpen(BodyWeightOpen open) {
		double[][][] result = new double[Constants.LACT+1][Constants.MIM+1][Constants.MPREG+1];
		
		for(int lact=1; lact<=2; lact++){
			for(int mim=1; mim<=Constants.MIM; mim++){
				double abs = open.getAbsAdjustment()[lact];
				double pct = open.getPctAdjustment()[lact];
				double val = open.getBodyWeightOpen()[lact][mim];
				result[lact][mim][0] = (val * (1 + pct)) + abs;
			}
		}
		
		return result;
	}
	
	public boolean updateBodyWeightOpen(int fileNo, BodyWeightOpen obj){
		return dao.updateBodyWeightOpen(fileNo, obj);
	}
	
}